package com.huiyeji.hui.vo;

import com.huiyeji.hui.exception.ValidationException;

import javax.validation.constraints.Pattern;

/**
 * @author zhaoduo
 */
public class PwdChangeVo {

    @Pattern(regexp = "^[0-9a-zA-Z.]{6,16}$",message = "旧密码不合法")
    private String oldPwd;

    @Pattern(regexp = "^[0-9a-zA-Z.]{6,16}$",message = "新密码不合法")
    private String newPwd;

    @Pattern(regexp = "^[0-9a-zA-Z.]{6,16}$",message = "确认密码不合法")
    private String confirmPwd;

    public String getOldPwd() {
        return oldPwd;
    }

    public void setOldPwd(String oldPwd) {
        this.oldPwd = oldPwd;
    }

    public String getNewPwd() {
        return newPwd;
    }

    public void setNewPwd(String newPwd) {
        this.newPwd = newPwd;
    }

    public String getConfirmPwd() {
        return confirmPwd;
    }

    public void setConfirmPwd(String confirmPwd) {
        this.confirmPwd = confirmPwd;
    }

    /**
     * 检查并抛错
     * 两次输入密码必须相同
     * 新密码必须不等于旧密码
     */
    public void check(){
        if (!newPwd.equals(confirmPwd)){
            throw new ValidationException("新密码与确认密码不相同");
        }

        if (newPwd.equals(oldPwd)){
            throw new ValidationException("新密码不能与旧密码相同");
        }
    }
}
